local addonName,ns = ...
local L = ns.L
ns.AurayOffset = -5	--用于存光环表内行数
ns.AurarowFrames = {}--用于存表的行框架,方便查询和删除后重新排序

--光环表格行
function ns.AddAuraTableButtons(frame,id,name)
	if ns.AurarowFrames[id] then return end
	local rowFrame = CreateFrame("Frame", nil, frame)
    rowFrame:SetSize(610, 26)
    rowFrame:SetPoint("TOPLEFT", 5, ns.AurayOffset)
	ns.AurarowFrames[id] = rowFrame -- 将行 Frame 存储起来
	local rowFramebackground = rowFrame:CreateTexture(nil, "BACKGROUND")
	rowFramebackground:SetTexture(130937)
	rowFramebackground:SetAllPoints(rowFrame) -- 使背景纹理与字体字符串大小相同
	rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3) -- 设置背景颜色为黑色，透明度为0.5
	rowFramebackground:SetScript("OnEnter", function(self)
		self:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	rowFramebackground:SetScript("OnLeave", function(self)
		self:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
    -- 创建字体字符串
	local TABLECOLOR = ns.AddColorFrame(rowFrame, 2, -2, nil,53,23, "Auras",id,"color") --创建色块
	TABLECOLOR:HookScript("OnEnter", function(self)
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	TABLECOLOR:HookScript("OnLeave", function(self)
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
	local background1 = rowFrame:CreateTexture(nil, "ARTWORK")
	background1:SetTexture(130937)
	background1:SetPoint("LEFT", 58, 0)
	background1:SetSize(62,23)
	background1:SetColorTexture(0, 0, 0, .5) -- 设置背景颜色为黑色，透明度为0.5
	local font1 = rowFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
	font1:SetPoint("LEFT",background1,"LEFT", 3, 0)
	font1:SetText(id)
	font1:SetFont(ns.fonts, 15, "OUTLINE")

	local background3 = rowFrame:CreateTexture(nil, "ARTWORK")
	background3:SetTexture(130937)
	background3:SetPoint("LEFT", 123, 0)
	background3:SetSize(120,23)
	background3:SetColorTexture(0, 0, 0, .5)
	
	local icon = ns.GetSpellIcon(id)
	local font3 = rowFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
	font3:SetPoint("LEFT",background3,"LEFT", 3, 0)
	font3:SetText("|T"..icon ..":18|t "..name)
	font3:SetFont(ns.fonts, 15, "OUTLINE")
	
	local cengshu = ns.AddTableNotes(rowFrame,14,"Auras",id,"stack")
	
	local check1 = ns.AddTableClick(rowFrame,82,L["光环列表行血条"],"Auras",id,"usehp")
	check1.check:HookScript("OnEnter", function ()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	check1.check:HookScript("OnLeave", function()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
	local check2 = ns.AddTableClick(rowFrame,150,L["光环列表行名字"],"Auras",id,"usename")
	check2.check:HookScript("OnEnter", function ()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	check2.check:HookScript("OnLeave", function()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
	--[[
	local check3 = ns.AddTableClick(rowFrame,150,L["光环列表行边框"],"Auras",id,"useborder")
	check3.check:HookScript("OnEnter", function ()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	check3.check:HookScript("OnLeave", function(self)
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)]]
	local check4 = ns.AddTableClick(rowFrame,218,L["光环列表行网格"],"Auras",id,"usetexture")
	check4.check:HookScript("OnEnter", function ()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	check4.check:HookScript("OnLeave", function(self)
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
	local check5 = ns.AddTableClick(rowFrame,286,L["光环列表行隐藏"],"Auras",id,"usehide")
	check5.check:HookScript("OnEnter", function ()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	check5.check:HookScript("OnLeave", function()
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
	local closeButton = CreateFrame("Button", nil, rowFrame, "UIPanelCloseButton")
	closeButton:SetPoint("RIGHT", 0, 0)
	closeButton:SetScript("OnClick", function()
		PlateColorDB["Auras"][id] = true -- 移除对应的表格内容
        rowFrame:Hide() -- 隐藏这一行
        local newOffset = -5
		for key, row in pairs(ns.AurarowFrames) do
			if key and row:IsShown() and rowFrame~= row then -- 只对显示的行重新定位
            row:SetPoint("TOPLEFT", 5, newOffset)
            newOffset = newOffset - 28
			ns.AurayOffset = newOffset
		end
		ns.AurarowFrames[id] = nil
    end
	end)
	closeButton:SetScript("OnEnter", function(self)
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 1)
	end)
	closeButton:SetScript("OnLeave", function(self)
		rowFramebackground:SetColorTexture(0.5, 0.5, 0.5, 0.3)
	end)
	ns.AurayOffset = ns.AurayOffset - 28
	return rowFrame
end